package animix.blue.server.user.mapper;


import animix.blue.server.common.bean.model.UserRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserRoleMapper {

    @Select("select * from tb_user_role where user_id = #{userId}")
    public List<UserRole> listByUserId(Integer userId);

    @Delete("delete from tb_user_role where user_id = #{userId}")
    public void deleteByUserId(Integer userId);

    @Insert({
            "<script>",
            "insert into tb_user_role (user_id, role_id, created, updated) values",
            "<foreach collection='listUserRole' item='userRole' index='index' separator=','>",
            "(#{userRole.userId}, #{userRole.roleId}, #{userRole.created}, #{userRole.updated})",
            "</foreach>",
            "</script>"
    })
    public void insertBatch(@Param("listUserRole") List<UserRole> listUserRole);
}
